import { get, post, put, del } from '@/utils/request'

// 获取产品列表
export const getProductList = (params?: any) => {
  return get('/api/Products/GetProductList', params)
}

// 获取产品详情
export const getProductDetail = (id: number) => {
  return get('/api/Products/GetProductById', { id })
}

// 创建产品
export const createProduct = (data: any) => {
  return post('/api/Products/CreateProduct', data)
}

// 更新产品
export const updateProduct = (data: any) => {
  return put('/api/Products/UpdateProduct', data)
}

// 删除产品
export const deleteProduct = (id: number) => {
  return del('/api/Products/DeleteProduct', { id })
}

// 批量删除产品
export const batchDeleteProduct = (ids: number[]) => {
  return post('/api/Products/BatchDeleteProduct', ids)
}

// 导入产品
export const importProduct = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  const config: any = {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }
  return post('/api/Products/ImportProduct', formData, config)
}

// 导出产品
export const exportProduct = (params?: any) => {
  const config: any = {
    responseType: 'blob',
    headers: {}
  }
  return get('/api/Products/ExportProduct', params, config)
}

// 上传产品图片
export const uploadProductImage = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  const config: any = {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }
  return post('/api/Products/UploadImage', formData, config)
}